<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Test02</title>
    <script src="https://unpkg.com/vue/dist/vue.js" type="text/javascript"></script>
</head>
<body>
<script id="template01" type="text/x-template">
    <div>
        {{compTitle}}: <input v-model="counter">
        <button @click="incrementCounter">Click</button>
    </div>
</script>
<!--<template id="template01">-->
<!--    <div>-->
<!--        <input>-->
<!--        <button>Click</button>-->
<!--    </div>-->
<!--</template>-->

<div id="app">
    <!--    <text-btn comp-title="TL01"></text-btn>-->
    <!--    <text-btn comp-title="TL02"></text-btn>-->
    <!--    <text-btn comp-title="TL03"></text-btn>-->
    <p>Total: {{total}}</p>

    <text-btn :comp-title="item.title" :key="item.key" @counter-event="countTotal" v-for="item in titles"></text-btn>

    <button @click="click">Test</button>

</div>

<script>
    Vue.component('text-btn', {
        template: '#template01',
        props: ['compTitle'],
        data: function () {
            return {
                counter: 0,
            }
        },
        methods: {
            incrementCounter: function () {
                this.counter++;
                this.$emit('counter-event', this.counter);
            }
        }
    });

    let vm = new Vue({
        el: '#app',
        data: {
            message: '',
            total: 0,
            titles: [
                {title: 'TL01', key: 'key01'},
                {title: 'TL02', key: 'key02'},
                {title: 'TL03', key: 'key03'},
            ]
        },
        methods: {
            click: function () {
                // vm.titles.push({title: 'TL04', key: 'key04'});
                Vue.set(this.titles[0], 'title', 'TL001');
            },
            countTotal: function (val) {
                this.total++;
                alert(val);
            }
        }
    });


</script>

</body>
</html>